<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML >
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>添加教师</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	
    <%@include file="/pages/head/head.jsp" %>
     
  </head>
  
  <body>
   <div id="wrapper">
        <!-- 左边菜单 -->
         <%@include file="/pages/left/leftmenu.jsp" %>

        <div id="page-wrapper" class="gray-bg dashbard-1">
             <!-- 引入top菜单 -->
              <%@include file="/pages/left/topmenu.jsp" %>
            
            <!--左边内容开发，开始  -->
              <div class="row wrapper border-bottom white-bg page-heading">
                <div class="col-lg-10">
                    <h2>教师资料</h2>
                    <ol class="breadcrumb">
                        <li>
                            <a href="index.html">主页</a>
                        </li>
                        <li>
                            <a>教师资料</a>
                        </li>
                        <li>
                            <strong>添加教师资料</strong>
                        </li>
                    </ol>
                </div>
                <div class="col-lg-2">

                </div>
            </div>
            <div class="wrapper wrapper-content animated fadeInRight">
                
                <div class="row">
                    <div class="col-lg-14">
                        <div class="ibox float-e-margins">
                            <div class="ibox-title">
                                <h5>添加教师资料</h5>
                                <div class="ibox-tools">
                                    <a class="collapse-link">
                                        <i class="fa fa-chevron-up"></i>
                                    </a>
                                </div>
                            </div>
                            <div class="ibox-content">
                                <form class="form-horizontal m-t" id="teachers" name="teachers" method="post" >
                                
                                    <div class="form-group">
                                        <label class="col-sm-3 control-label">教师编号：</label>
                                        <div class="col-sm-8">
                                            <input id="tcno" name="tcno"  maxlength="30"  class="form-control" type="text">
                                            <input id="tc_id" name="tc_id"  maxlength="30"  class="form-control" type="hidden">
                                            <input id="password" name="password"  maxlength="30"  class="form-control" type="hidden">
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-sm-3 control-label">教师名称：</label>
                                        <div class="col-sm-8">
                                            <input id="tcname" name="tcname" maxlength="30" class="form-control" type="text">
                                        </div>
                                    </div>
                                    
                                     <div class="form-group">
                                        <label class="col-sm-3 control-label">性别：</label>
                                        <div class="col-sm-8">
                                            <select class="form-control m-b" name="sex">
                                            	<option value="0">--请选择--</option>
                                                <option value="1" >男</option>
                                                <option value="2" >女</option>
                                            </select>
                                        </div>
                                    </div>
                                   
                                    <div class="form-group">
                                        <label class="col-sm-3 control-label">手机号码：</label>
                                        <div class="col-sm-8">
                                            <input id="phone" name="phone" class="form-control" type="text" aria-required="true" aria-invalid="true" class="error">
                                        </div>
                                    </div>
                                    
                                    <div class="form-group">
                                        <label class="col-sm-3 control-label">邮箱：</label>
                                        <div class="col-sm-8">
                                            <input type="text" id="email" name="email" class="form-control mail" />
                                            <script>
												$("#xemail").emailMatch();
											</script>
                                        </div>
                                    </div>
                                    
                                    <div class="form-group">
                                        <div class="col-sm-8 col-sm-offset-3">
                                            <button class="btn btn-primary" id="submitbutton" onclick="checkFyFhSubmit()" type="button">提交</button>
                                        </div>
                                    </div>
                                </form>
                            </div>
                        </div>
                    </div>
                </div>

            </div>
         

        </div>
    </div>
     <%@include file="/pages/head/foot.jsp" %>
    
      <!-- simditor -->

    <script>
    
        
        /** 表单验证  **/
    	function validateForm(){
    		if($("#tcno").val()==""){
    			alert("教师编号不可以为空");
    			return false;
    		}
    		if($("#tcname").val()==""){
    			alert("教师名称不可以为空");
    			return false;
    		}
    		if($("#sex").val()=="0"){
    			alert("请选择性别");
    			return false;
    		}
    		
    		return true;
    	}
    	
    	 function checkFyFhSubmit(){
    		 if(validateForm()){
    			 
    			 $.ajax({
    					type:"POST",
    					url:"${pageContext.request.contextPath}/teacher/addTeachers.do",
    					data:$("#teachers").serialize(),
    					async: true,
    					dataType: "text", 
    		  			error: function(request) {alert("添加信息失败！"+request.responseText);},
    					success:function(data){
    						var result=String($.trim(data));
    						if(result == "succ"){
    							alert("操作成功");
    							window.location.href="./pages/teacher/addTeacher.jsp";
    						}
    						else{
    							alert("操作失败：教师编号不能重复");
    						}
    						
    					}
    				});
    			 
    		 }
    		
		//return true;
    	} 
    	
    	 $(function(){  
   		  
    		 //文本框只能输入数字，并屏蔽输入法和粘贴  
    		 $.fn.numeral = function() {     
    		            $(this).css("ime-mode", "disabled");     
    		            this.bind("keypress",function(e) {     
    		            var code = (e.keyCode ? e.keyCode : e.which);  //兼容火狐 IE      
    		              /*   if(!$.browser.msie&&(e.keyCode==0x8))  //火狐下不能使用退格键     
    		                {     
    		                     return ;     
    		                    }   */   
    		                    return code >= 48 && code<= 57;     
    		            });     
    		            this.bind("blur", function() {     
    		                if (this.value.lastIndexOf(".") == (this.value.length - 1)) {     
    		                    this.value = this.value.substr(0, this.value.length - 1);     
    		                } else if (isNaN(this.value)) {     
    		                    this.value = "";     
    		                }     
    		            });     
    		            this.bind("paste", function() {     
    		                var s = clipboardData.getData('text');     
    		                if (!/\D/.test(s));     
    		                value = s.replace(/^0*/, '');     
    		                return false;     
    		            });     
    		            this.bind("dragenter", function() {     
    		                return false;     
    		            });     
    		            this.bind("keyup", function() {     
    		            if (/(^0+)/.test(this.value)) {     
    		                this.value = this.value.replace(/^0*/, '');     
    		                }     
    		            });     
    		        };    
    		        //调用文本框的id  
    		  $("#phone").numeral();   
    		  
    		}); 
    </script>
  </body>
</html>
